package com.funever.adapter;

import com.funever.myyouku.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MenuListAdapter extends BaseAdapter {
	
	private Context ctx;
	
	String[] titles;
	
	public MenuListAdapter(Context ctx){
		this.ctx = ctx;
		titles = ctx.getResources().getStringArray(R.array.menu_item_title);
	}

	@Override
	public int getCount() {
		return titles.length;
	}

	@Override
	public Object getItem(int position) {
		return titles[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView!=null){
			holder = (ViewHolder) convertView.getTag();
		}else{
			convertView = LayoutInflater.from(ctx).inflate(R.layout.menu_item_layout, null);
			TextView title = (TextView) convertView.findViewById(R.id.title);
			holder = new ViewHolder();
			holder.title = title;
			convertView.setTag(holder);
		}
		holder.title.setText(titles[position]);
		return convertView;
	}
	
	class ViewHolder{
		TextView title;
	}

}
